﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DispatchAssist.BusinessLogical.Model;

namespace DispatchAssist.Model
{
    public class NormalAlertInfo
    {

        /// <summary>
        /// 唯一标识
        /// </summary>
        public Guid AlertID { get; set; }

        /// <summary>
        /// 告警行为
        /// </summary>
        public int AlertActionFlag { get; set; }

        public int PerformActionFlag { get; set; }

        /// <summary>
        /// 告警机场关系，如：计划降落场、起飞备降场
        /// </summary>
        public string AirportRelation { get; set; }

        /// <summary>
        /// 承运人
        /// </summary>
        public string Carrier { get; set; }

        /// <summary>
        /// 航班号
        /// </summary>
        public string FlightNo { get; set; }

        /// <summary>
        /// 飞机尾号
        /// </summary>
        public string TailNo { get; set; }

        /// <summary>
        /// 起始站
        /// </summary>
        public string DeptAirport { get; set; }

        /// <summary>
        /// 到达站
        /// </summary>
        public string ArrAirport { get; set; }

        /// <summary>
        /// 预警机场
        /// </summary>
        public string Airport { get; set; }

        /// <summary>
        /// 预警时间
        /// </summary>
        public DateTime WarnTime { get; set; }

        /// <summary>
        /// 预警级别
        /// </summary>
        public int WarnLevel { get; set; }

        /// <summary>
        /// 预警原始报文
        /// </summary>
        public string WarnMsg { get; set; }

        /// <summary>
        /// 中文气象预警信息
        /// </summary>
        public string WarnInfo { get; set; }


        /// <summary>
        /// 计划起飞时间
        /// </summary>
        public DateTime PlanDeptTime { get; set; }

        /// <summary>
        /// 计划到达时间
        /// </summary>
        public DateTime PlanArrTime { get; set; }

        /// <summary>
        /// 预计起飞时间
        /// </summary>
        public DateTime? EstDeptTime { get; set; }

        /// <summary>
        /// 预计到达时间
        /// </summary>
        public DateTime? EstArrTime { get; set; }

        /// <summary>
        /// 实际起飞时间
        /// </summary>
        public DateTime? RealDeptTime { get; set; }

        /// <summary>
        /// 实际到达时间
        /// </summary>
        public DateTime? RealArrTime { get; set; }

        public Guid SeatID { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string SeatName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string MAC { get; set; }

        /// <summary>
        /// 机场名
        /// </summary>
        public string AirportFullName { get; set; }

        /// <summary>
        /// 模板内容
        /// </summary>
        public string MsgTemplateContent { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string MessageBody
        {
            get;
            set;
        }

        /// <summary>
        /// 等级名称
        /// </summary>
        public string WarnLevelName
        {
            get
            {
                switch (WarnLevel)
                {
                    case 1:
                        return "红色预警";
                    case 2:
                        return "橙色预警";
                    case 3:
                        return "蓝色预警";
                    default:
                        return "";
                }

            }
        }

        public NormalAlertInfo CopyModel()
        {
            NormalAlertInfo info = new NormalAlertInfo();

            info.Airport = this.Airport;
            info.AirportFullName = this.AirportFullName;
            info.AirportRelation = this.AirportRelation;
            info.AlertActionFlag = this.AlertActionFlag;
            info.AlertID = this.AlertID;
            info.ArrAirport = this.ArrAirport;
            info.Carrier = this.Carrier;
            info.DeptAirport = this.DeptAirport;
            info.FlightNo = this.FlightNo;
            info.MAC = this.MAC;
            info.MessageBody = this.MessageBody;
            info.MsgTemplateContent = this.MsgTemplateContent;
            info.SeatID = this.SeatID;
            info.SeatName = this.SeatName;
            info.TailNo = this.TailNo;
            info.WarnInfo = this.WarnInfo;
            info.WarnLevel = this.WarnLevel;
            info.WarnMsg = this.WarnMsg;
            info.WarnTime = this.WarnTime;

            info.PlanDeptTime = this.PlanDeptTime;
            info.PlanArrTime = this.PlanArrTime;
            info.EstDeptTime = this.EstDeptTime;
            info.EstArrTime = this.EstArrTime;
            info.RealDeptTime = this.RealDeptTime;
            info.RealArrTime = this.RealArrTime;

            return info;
        }

        public List<int> SplitActionFlags()
        {
            List<int> flags = new List<int>();

            if (((AlertActionFlag | (int)Enums.AlertActionFlag.BubbleAlert) == AlertActionFlag) && ((PerformActionFlag & (int)Enums.AlertActionFlag.BubbleAlert) == 0))
            {
                flags.Add((int)Enums.AlertActionFlag.BubbleAlert);
            }
            if (((AlertActionFlag | (int)Enums.AlertActionFlag.PromptAlert) == AlertActionFlag) && ((PerformActionFlag & (int)Enums.AlertActionFlag.PromptAlert) == 0))
            {
                flags.Add((int)Enums.AlertActionFlag.PromptAlert);
            }

            if (((AlertActionFlag | (int)Enums.AlertActionFlag.ManualSendAcrarsAlert) == AlertActionFlag) && ((PerformActionFlag & (int)Enums.AlertActionFlag.ManualSendAcrarsAlert) == 0))
            {
                flags.Add((int)Enums.AlertActionFlag.ManualSendAcrarsAlert);
            }

            if (((AlertActionFlag | (int)(Enums.AlertActionFlag.AutoSendAcarsAlert | Enums.AlertActionFlag.ConfirmAcars)) == AlertActionFlag) && ((PerformActionFlag & (int)Enums.AlertActionFlag.ConfirmAcars) == 0))
            {
                flags.Add((int)(Enums.AlertActionFlag.AutoSendAcarsAlert | Enums.AlertActionFlag.ConfirmAcars));
            }

            return flags;
        }

        public List<NormalAlertInfo> SplitModel()
        {
            List<int> actions = this.SplitActionFlags();

            List<NormalAlertInfo> result = new List<NormalAlertInfo>();
            foreach (int action in actions)
            {

                NormalAlertInfo info = this.CopyModel();
                info.AlertActionFlag = action;

                result.Add(info);
            }

            return result;
        }


    }
}
